import { ajhttp, upload } from '@/utils/http'
import { useTenantSystemStore } from '@/stores'

/**
 * 发送短信验证码
 */
export const sendSMSVerifyCode = (phone: string) => {
    const tenantStore = useTenantSystemStore()
    return ajhttp({
        method: 'POST',
        url: `/platform/common/SendSMSVerifyCode?pid=${tenantStore.state.pid}&phone=${phone}`,
    })
}

/**
 * 上传文件
 */
export const uploadFile = (filePath: string, customData: any) => {
    const tenantStore = useTenantSystemStore()
    return upload(filePath, customData, {
        method: 'POST',
        url: `/platform/common/upload?pid=${tenantStore.state.pid}`,
    })
}

/**
 * 按url删除文件
 */
export const deleteFiles = (url: Array<string>) => {
    const tenantStore = useTenantSystemStore()
    return ajhttp({
        method: 'POST',
        url: `/platform/common/removeMedias?pid=${tenantStore.state.pid}`,
        data: {
            url
        }
    })
}

/**
 * 获取指定名称的系统枚举信息
 */
export const enumOptions = (name: string) => {
    const tenantStore = useTenantSystemStore()
    return ajhttp({
        method: 'GET',
        url: `/platform/common/enum?pid=${tenantStore.state.pid}&name=${name}`,
    })
}

/**
 * 获取省市区数据源
 */
export const cities = (includeRegion: boolean = false) => {
    const tenantStore = useTenantSystemStore()
    return ajhttp({
        method: 'GET',
        url: `/platform/common/cities?pid=${tenantStore.state.pid}&includeRegion=${includeRegion}`,
    })
}